import type { ExtractPublicPropTypes, PropType } from 'vue';
import { tableProps } from 'ant-design-vue/es/table';
import { TableColumnProps } from 'ant-design-vue';
import { ResponseData, Columns } from './interface';
import {
  array,
  bool,
  func,
  number,
  oneOf,
  oneOfType,
  object,
  string,
} from 'vue-types';

const proTableProps = () => ({
  ...tableProps(),
  align: string<Exclude<TableColumnProps['align'], undefined>>().def('center'),
  request:
    func<(params?: any) => Promise<ResponseData> | ResponseData>().isRequired,
  autoload: bool().def(true),
  hideSearch: bool().def(false),
  hidePagination: bool().def(false),
  height: oneOfType([oneOf(['auto'] as const), number()]),
  pageSizeOptions: oneOfType([array<string>(), array<number>()]).def([
    '15',
    '30',
    '45',
  ]),
  columns: array<Columns>().def([]),
  showIndex: oneOfType([
    bool(),
    object<{ fixed: boolean | 'left' | 'right' }>(),
  ]).def(false),
});

export const props = proTableProps() as ReturnType<typeof proTableProps>;
